package adfc2.actions;

import adfc2.core.Creature;
import adfc2.core.Item;
import adfc2.entities.Workshop;

/**
 * Действие - взять предмет из объекта (контейнера, мастерской, и пр.)
 */
public class TakeAction extends InstantAction {

    public final Item item;

    public TakeAction(Creature actor, Item item) {
        super(actor);
        this.item = item;
    }

    @Override
    protected boolean perform() {
        assert (item.owner != actor);
        assert (item.owner != null);
        if (item.owner instanceof Workshop) {
            Workshop workshop = (Workshop) item.owner;
            if (actor.getXY() != workshop.getEntranceXY()) return false;
            workshop.removeItem(item);
            actor.addItem(item);
            return true;
        } else return false; // TODO другие типы
    }
}
